package algorithm.swordoff;

import java.util.Stack;

/**
 * 包含min函数的栈
 * 本题与主站 155 题相同
 *
 * 用一个尾端最小的辅助栈
 */

public class SQ30 {
}

class MinStack {

    Stack<Integer> minStack;
    Stack<Integer> container;

    /** initialize your data structure here. */
    public MinStack() {
        minStack = new Stack<>();
        container = new Stack<>();
    }

    public void push(int x) {
        container.push(x);
        if (minStack.isEmpty()) {
            minStack.push(x);
        } else {
            if (minStack.peek() < x) minStack.push(minStack.peek());
            else minStack.push(x);
        }

    }

    public void pop() {
        container.pop();
        minStack.pop();
    }

    public int top() {
        return container.peek();
    }

    public int min() {
        return minStack.peek();
    }
}